package com.wms.wstatus.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.wms.common.util.CommonTools;
import com.wms.common.web.action.CIBaseAction;
import com.wms.db.bean.StatusPerson;
import com.wms.db.bean.User;
import com.wms.wstatus.service.WStatusService;

public class WStatusAction extends CIBaseAction {
	private Logger logger = Logger.getLogger(this.getClass());
	
	private WStatusService wstatusService;
	
	private List<String> pstatus;

	private List<String> mstatus;
	
	private List<String> tstatus;
	
	private List<StatusPerson> ps;

	public String toWStatus() throws Exception {
		String username = this.getSessionUserInfo().getUsername();
		pstatus = new ArrayList<String>();
		List<StatusPerson> sp = wstatusService.getPStatusByName(username);
		for(StatusPerson s:sp){
			pstatus.add(s.getStatus());
		}
		return SUCCESS;
	}
	
	public String doWStatus() throws Exception{
		String username = this.getSessionUserInfo().getUsername();
		List<StatusPerson> sp = new ArrayList<StatusPerson>();
		
		if(null != pstatus){
			int i=1;
			for(String status:pstatus){
				if(null==status || "".equals(status)) continue;
				StatusPerson s = new StatusPerson();
				s.setStatus(status);
				s.setTime(CommonTools.getMondayDate(new Date()));
				s.setUser(new User(username));
				s.setIdx(i++);
				sp.add(s);
			}
			wstatusService.savePStatus(sp);
		}
		return SUCCESS;
	}

	public void setWstatusService(WStatusService wstatusService) {
		this.wstatusService = wstatusService;
	}

	public WStatusService getWstatusService() {
		return wstatusService;
	}
	
	public List<String> getPstatus() {
		return pstatus;
	}

	public void setPstatus(List<String> pstatus) {
		this.pstatus = pstatus;
	}

	public void setMstatus(List<String> mstatus) {
		this.mstatus = mstatus;
	}

	public List<String> getMstatus() {
		return mstatus;
	}

	public void setTstatus(List<String> tstatus) {
		this.tstatus = tstatus;
	}

	public List<String> getTstatus() {
		return tstatus;
	}
}
